<%@ page language="java" import="java.util.*,com.zxl.util.*,org.jfree.chart.ChartFactory,org.jfree.chart.JFreeChart,org.jfree.chart.plot.PlotOrientation,org.jfree.chart.servlet.ServletUtilities,org.jfree.data.category.DefaultCategoryDataset,org.jfree.chart.title.TextTitle,java.awt.Font,org.jfree.chart.plot.CategoryPlot,org.jfree.chart.axis.CategoryAxis,org.jfree.chart.axis.ValueAxis" pageEncoding="UTF-8"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="org.jfree.chart.axis.CategoryLabelPositions"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
	DBTools dbt = new DBTools();
	List datalist = dbt.GetTotalData();
	DefaultCategoryDataset dataset = new DefaultCategoryDataset();
	for (int i = 0; i < datalist.size(); i++) {
		HashMap hm = (HashMap) datalist.get(i);
		String sheng = (String) hm.get("sheng").toString();
		double renwu = 0;
		if(hm.get("renwu") != null){
			renwu = Double.parseDouble((String) hm.get("renwu").toString());
		}
		dataset.addValue(renwu, i + "", sheng);
	}
	JFreeChart chart = ChartFactory.createBarChart3D("各省项目进度统计图",
			"省份名称", "项目进度（%）", dataset, PlotOrientation.VERTICAL,
			false, false, false);

	String graphURL = "";
	String filename = "";
	//Font cFont = Font.createFont(Font.PLAIN, new FileInputStream(this
			//.getClass().getClassLoader().getResource("").getPath()
			//+ "/simkai.ttf"));
	Font cFont = new Font("宋体", Font.PLAIN, 30);
	
	chart.setTitle(new TextTitle("各省项目进度统计图", cFont.deriveFont(30F)));
	Font labelFont = cFont.deriveFont(20F);
	Font noFont = cFont.deriveFont(14F);
	CategoryPlot plot = chart.getCategoryPlot();
	//x轴
	CategoryAxis domainAxis = plot.getDomainAxis();
	domainAxis.setLabelFont(labelFont);// 轴标题
	domainAxis.setTickLabelFont(noFont);// 轴数值
	domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);//轴标题倾斜45度
	//y轴
	ValueAxis rangeAxis = plot.getRangeAxis();
	rangeAxis.setLabelFont(labelFont);
	rangeAxis.setTickLabelFont(noFont);

	//System.out.println(chart.getTitle().getFont());
	//System.out.println(domainAxis.getLabelFont());
	//System.out.println(chart.getTitle().getFont().getFamily());

	filename = ServletUtilities.saveChartAsPNG(chart, 800, 600, null,
			session);
	graphURL = request.getContextPath() + "/DisplayChart?filename="
			+ filename;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'jfreechart.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <div style="text-align:center;">
    	<img src="<%=graphURL%>"width=800 height=600 border=0 usemap="#<%= filename %>">
    </div>
  </body>
</html>
